<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const date = new Date();
        console.log(date);
        console.log(date * 1); // 转为时间戳
        console.log(Number(date)); // 转为时间戳
        console.log(date.getTime()); // 转为时间戳
        console.log(date.valueOf()); // 转为时间戳
        const timestamp = date.getTime();
        console.log(new Date(timestamp));
        console.time('for')
        for (let i = 0; i < 1000; i++) {

        }
        console.timeEnd('for')

        // 日期格式化
        const date0 = new Date();
        function formatDate(date, format = "YYYY-MM-DD HH:mm:ss") {
            const config = {
                YYYY: date.getFullYear(),
                MM: date.getMonth() + 1,
                DD: date.getDate(),
                HH: date.getHours(),
                mm: date.getMinutes(),
                ss: date.getSeconds()
            }
            for(let key in config){
                format = format.replace(key,config[key])
            }
            return format;
        }
        
        console.log(formatDate(date0,'YYYY年MM月DD日 HH:mm:ss'));;

    </script>
</body>

</html>